package mr

//
// RPC definitions.
//
// remember to capitalize all names.
//

import (
	"os"
	"strconv"
)

//
// example to show how to declare the arguments
// and reply for an RPC.
//

type ExampleArgs struct {
	X int
}

type ExampleReply struct {
	Y int
}

// Add your RPC definitions here.

//worker 向 coordinator获取任务的结构体
type Task struct {
	TaskType   TaskType //用于区分任务是worker OR reducer
	TaskId     int      //任务id
	FileName   string   //map输入文件
	FileSlice  []string //reduce输入文件
	ReducerNum int      //reducer任务的数量
}

//rpc调用时传递的参数
type TaskArgs struct{}

//用于区分任务是worker OR reducer
type TaskType int

//用于区分分配任务阶段
type Phase int

//用于区分任务状态
type State int

//枚举任务类型
const (
	MapTask     TaskType = iota //map任务
	ReduceTask                  //reduce任务
	WaitingTask                 //协调器已经将任务发放完毕，但是任务还没有完成
	ExitTask                    //所有任务都完成
)

//枚举分配任务阶段
const (
	MapPhase Phase = iota
	ReducePhase
	AllDone
)

//枚举任务状态
const (
	Working State = iota
	Waiting
	Done
)

// Cook up a unique-ish UNIX-domain socket name
// in /var/tmp, for the coordinator.
// Can't use the current directory since
// Athena AFS doesn't support UNIX-domain sockets.
func coordinatorSock() string {
	s := "/var/tmp/824-mr-"
	s += strconv.Itoa(os.Getuid())
	return s
}
